import Vue from 'vue';
import Router from 'vue-router';
import Layout from '@/layout/index.vue';
import {
  getToken,
  setToken,
  removeToken,
  getStoreId,
  setStoreId,
  removeStoreId,
  setUserInfo,
  getUserInfo,
  removeUserInfo
} from '@/utils/cookies';
import store from '@/store';

Vue.use(Router);

const router = new Router({
  scrollBehavior: (to, from, savedPosition) => {
    if (savedPosition) {
      return savedPosition;
    }
    return { x: 0, y: 0 };
  },
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/login',
      component: () =>
        import(/* webpackChunkName: 'login' */ '@/views/login/index.vue'),
      meta: { title: '英语口语学习系统', hidden: true, notNeedAuth: true }
    },
    {
      path: '/404',
      component: () => import(/* webpackChunkName: '404' */ '@/views/404.vue'),
      meta: { title: '英语口语学习系统', hidden: true, notNeedAuth: true }
    },
    {
      path: '/',
      component: Layout,
      redirect: '/dashboard',
      children: [
        {
          path: 'dashboard',
          component: () =>
            import(/* webpackChunkName: 'dashboard' */ '@/views/dashboard/index.vue'),
          name: 'Dashboard',
          meta: {
            title: '个人信息',
            icon: 'dashboard',
            affix: true
          }
        },
       {
          path: '/statistics',
          component: () =>
            import(/* webpackChunkName: 'shopTable' */ '@/views/statistics/index.vue'),
          meta: {
            title: '数据统计',
            icon: 'icon-statistics'
          }
        },
        {
          path: 'order',
          component: () =>
            import(/* webpackChunkName: 'shopTable' */ '@/views/orderDetails/index.vue'),
          meta: {
            title: '订阅管理',
            icon: 'icon-order'
          }
        },
        {
          path: 'dish',
          component: () =>
            import(/* webpackChunkName: 'shopTable' */ '@/views/dish/index.vue'),
          meta: {
            title: '文章首页',
            icon: 'icon-dish'
          }
        },
        {
          path: 'category',
          component: () =>
            import(/* webpackChunkName: 'shopTable' */ '@/views/category/index.vue'),
          meta: {
            title: '分类导航',
            icon: 'icon-category'
          }
        },
      ]
    },
    {
      path: '*',
      redirect: '/404',
      meta: { hidden: true }
    },
    {
      path: '/dish/:id', // 动态路由，:id 表示文章的 ID
      name: 'detail',
      component: () => import('@/views/dish/detail.vue'), // 文章详情页的组件路径
      meta: {
        title: '文章详情', // 页面标题
      },
    }
  ]
});

export default router;
